package cn.iocoder.yudao.module.infra.controller.admin.infocolumncollect;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.infra.controller.admin.infocolumncollect.vo.*;
import cn.iocoder.yudao.module.infra.dal.dataobject.infocolumncollect.InfoColumnCollectDO;
import cn.iocoder.yudao.module.infra.convert.infocolumncollect.InfoColumnCollectConvert;
import cn.iocoder.yudao.module.infra.service.infocolumncollect.InfoColumnCollectService;

@Tag(name = "管理后台 - 基础资料表元素汇总")
@RestController
@RequestMapping("/infra/info-column-collect")
@Validated
public class InfoColumnCollectController {

    @Resource
    private InfoColumnCollectService infoColumnCollectService;

    @PostMapping("/create")
    @Operation(summary = "创建基础资料表元素汇总")
    @PreAuthorize("@ss.hasPermission('infra:info-table-collect:create')")
    public CommonResult<Long> createInfoColumnCollect(@Valid @RequestBody InfoColumnCollectCreateReqVO createReqVO) {
        return success(infoColumnCollectService.createInfoColumnCollect(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新基础资料表元素汇总")
    @PreAuthorize("@ss.hasPermission('infra:info-table-collect:update')")
    public CommonResult<Boolean> updateInfoColumnCollect(@Valid @RequestBody InfoColumnCollectUpdateReqVO updateReqVO) {
        infoColumnCollectService.updateInfoColumnCollect(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除基础资料表元素汇总")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('infra:info-table-collect:delete')")
    public CommonResult<Boolean> deleteInfoColumnCollect(@RequestParam("id") Long id) {
        infoColumnCollectService.deleteInfoColumnCollect(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得基础资料表元素汇总")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('infra:info-table-collect:query')")
    public CommonResult<InfoColumnCollectRespVO> getInfoColumnCollect(@RequestParam("id") Long id) {
        InfoColumnCollectDO infoColumnCollect = infoColumnCollectService.getInfoColumnCollect(id);
        return success(InfoColumnCollectConvert.INSTANCE.convert(infoColumnCollect));
    }

//    @GetMapping("/list")
//    @Operation(summary = "获得基础资料表元素汇总列表")
//    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
//    @PreAuthorize("@ss.hasPermission('infra:info-table-collect:query')")
//    public CommonResult<List<InfoColumnCollectRespVO>> getInfoColumnCollectList(@RequestParam("ids") Collection<Long> ids) {
//        List<InfoColumnCollectDO> list = infoColumnCollectService.getInfoColumnCollectList(ids);
//        return success(InfoColumnCollectConvert.INSTANCE.convertList(list));
//    }

    @GetMapping("/page")
    @Operation(summary = "获得基础资料表元素汇总分页")
    @PreAuthorize("@ss.hasPermission('infra:info-table-collect:query')")
    public CommonResult<PageResult<InfoColumnCollectRespVO>> getInfoColumnCollectPage(@Valid InfoColumnCollectPageReqVO pageVO) {
        PageResult<InfoColumnCollectDO> pageResult = infoColumnCollectService.getInfoColumnCollectPage(pageVO);
        return success(InfoColumnCollectConvert.INSTANCE.convertPage(pageResult));
    }

//    @GetMapping("/export-excel")
//    @Operation(summary = "导出基础资料表元素汇总 Excel")
//    @PreAuthorize("@ss.hasPermission('infra:info-column-collect:export')")
//    @OperateLog(type = EXPORT)
//    public void exportInfoColumnCollectExcel(@Valid InfoColumnCollectExportReqVO exportReqVO,
//              HttpServletResponse response) throws IOException {
//        List<InfoColumnCollectDO> list = infoColumnCollectService.getInfoColumnCollectList(exportReqVO);
//        // 导出 Excel
//        List<InfoColumnCollectExcelVO> datas = InfoColumnCollectConvert.INSTANCE.convertList02(list);
//        ExcelUtils.write(response, "基础资料表元素汇总.xls", "数据", InfoColumnCollectExcelVO.class, datas);
//    }

}
